<?php

/*
 * @Descripttion: 
 * @version: 1.0
 * @Author: Sam
 * @Date: 2022-04-21 15:27:09
 * @LastEditors: Sam
 * @LastEditTime: 2022-04-28 09:12:28
 */
use think\facade\Db;
use app\admin\model\AuthRule as AuthRuleModel;

if (!AuthRuleModel::where('title', '砍价管理')->count()) {

    $parent_id = AuthRuleModel::query()->create([
        'parent_id'    => 0,
        'title'        => '砍价管理',
        'url'          => '#',
        'method'       => 'OPTIONS',
        'slug'         => 'bargain'
    ]);
    $parent_id_1 =  AuthRuleModel::query()->create([
        'parent_id'    => $parent_id->id,
        'title'        => '砍价活动',
        'url'          => 'bargain_index',
        'method'       => 'GET',
        'slug'         => 'bargain.index'
    ]);
    $parent_id_2 =  AuthRuleModel::query()->create([
        'parent_id'    => $parent_id->id,
        'title'        => '砍价订单',
        'url'          => 'bargain_order',
        'method'       => 'GET',
        'slug'         => 'bargain.order'
    ]);
     AuthRuleModel::query()->create([
        'parent_id'    => $parent_id_2->id,
        'title'        => '订单详情',
        'url'          => 'bargain_order_detail',
        'method'       => 'GET',
        'slug'         => 'bargain.order_detail'
    ]);
    AuthRuleModel::query()->create([
        'parent_id'    => $parent_id_2->id,
        'title'        => '订单导出',
        'url'          => 'bargain_order_export',
        'method'       => 'GET',
        'slug'         => 'bargain.baragin_order_export'
    ]);
    $parent_id_3 =  AuthRuleModel::query()->create([
        'parent_id'    => $parent_id->id,
        'title'        => '砍价记录',
        'url'          => 'bargain_log',
        'method'       => 'GET',
        'slug'         => 'bargain.log'
    ]);

    AuthRuleModel::query()->create([
        'parent_id'    => $parent_id_3->id,
        'title'        => '砍价记录导出',
        'url'          => 'baragin_log_export',
        'method'       => 'GET',
        'slug'         => 'bargain.baragin_log_export'
    ]);
    AuthRuleModel::query()->create([
        'parent_id'    => $parent_id_1->id,
        'title'        => '添加砍价',
        'url'          => 'bargain_create',
        'method'       => 'POST',
        'slug'         => 'bargain.create'
    ]);
    AuthRuleModel::query()->create([
        'parent_id'    => $parent_id_1->id,
        'title'        => '编辑砍价',
        'url'          => 'bargain_edit',
        'method'       => 'POST',
        'slug'         => 'bargain.edit'
    ]);
    AuthRuleModel::query()->create([
        'parent_id'    => $parent_id_1->id,
        'title'        => '删除砍价',
        'url'          => 'bargain_delete',
        'method'       => 'POST',
        'slug'         => 'bargain.delete'
    ]);
}
